package com.dragon.mmochat.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.model.MmochatChenHao;
import com.dragon.mmochat.model.MmochatDailyActivity;
import com.dragon.mmochat.model.MmochatRolePayInfo;
import com.dragon.mmochat.model.enumType.MmochatChatChannelType;
import com.dragon.mmochat.model.enumType.MmochatChenHaoType;
import com.dragon.mmochat.model.enumType.MmochatDailyActivityType;
import com.dragon.mmochat.model.enumType.MmochatFamilyType;
import com.dragon.mmochat.model.enumType.MmochatGangSkillType;
import com.dragon.mmochat.model.enumType.MmochatLifeSkillType;
import com.dragon.mmochat.model.enumType.MmochatOtherSystemSettingType;
import com.dragon.mmochat.model.enumType.MmochatRoleType;
import com.dragon.mmochat.model.enumType.MmochatSecondRoleType;
import com.dragon.mmochat.model.enumType.MmochatShowRoleSet;
import com.dragon.mmochat.model.enumType.MmochatSkillType;
import com.dragon.mmochat.model.enumType.MmochatSpecialSkillType;
import com.dragon.mmochat.model.enumType.MmochatStorePwdState;
import com.dragon.mmochat.model.gang.MmochatGangSkill;
import com.dragon.mmochat.model.mergeServer.MergeStep1Model1;
import com.dragon.mmochat.model.mergeServer.MergeStep1Model4;
import com.dragon.mmochat.model.mergeServer.MergeStep2Model1;
import com.dragon.mmochat.model.object.MmochatPackageGrid;
import com.dragon.mmochat.model.object.MmochatPropEffect;
import com.dragon.mmochat.model.role.MmochatFriend;
import com.dragon.mmochat.model.role.MmochatPet;
import com.dragon.mmochat.model.role.MmochatPlayer;
import com.dragon.mmochat.model.role.MmochatRankPlayer;
import com.dragon.mmochat.model.role.MmochatSimplePlayer;
import com.dragon.mmochat.model.skill.MmochatSkill;
import com.dragon.mmochat.model.skill.MmochatSpecialSkill;
import com.dragon.mmochat.model.skill.lifeSkill.MmochatLifeSkill;
import com.dragon.mmochat.model.statistics.MmochatRoleLevelInfoStatistics;
import com.dragon.mmochat.model.task.MmochatTask;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class MmochatRoleDao extends SimpleJdbcDaoSupport {
	private static final RoleRowMapper roleMapper = new RoleRowMapper();
	private static final SimpleRoleRowMapper simpleRoleRowMapper = new SimpleRoleRowMapper();
	private static final RankRoleRowMapper rankRoleRowMapper = new RankRoleRowMapper();
	private static final RoleLevelInfoRowMapper roleLevelInfoRowMapper = new RoleLevelInfoRowMapper();
	private static final RolePayInfoRowMapper rolePayInfoMapper = new RolePayInfoRowMapper();
	private static final MergeStep2Model1Mapper mergeStep2Model1Mapper = new MergeStep2Model1Mapper();
	private static final MergeStep1Mapper mergeStep1Mapper = new MergeStep1Mapper();
	private static final MergeStep4Mapper mergeStep4Mapper = new MergeStep4Mapper();

	// TODO:TEST
	// public class TestModel {
	// int roleId;
	// Map<Integer, MmochatPackageGrid> myPackage;
	// Map<Integer, MmochatPackageGrid> myStorage;
	//
	// public int getRoleId() {
	// return roleId;
	// }
	//
	// public void setRoleId(int roleId) {
	// this.roleId = roleId;
	// }
	//
	// public Map<Integer, MmochatPackageGrid> getMyPackage() {
	// return myPackage;
	// }
	//
	// public void setMyPackage(Map<Integer, MmochatPackageGrid> myPackage) {
	// this.myPackage = myPackage;
	// }
	//
	// public Map<Integer, MmochatPackageGrid> getMyStorage() {
	// return myStorage;
	// }
	//
	// public void setMyStorage(Map<Integer, MmochatPackageGrid> myStorage) {
	// this.myStorage = myStorage;
	// }
	//
	// }
	//
	// private static final TestMapper testMap = new TestMapper();
	//
	// private static final String testSql =
	// "select id, package, storage from role "
	// + "where id >= ? and id < ? and latest_login_time > 1330876800562";
	//
	// public List<TestModel> test(int s, int e) {
	// return getSimpleJdbcTemplate().query(testSql, testMap, s, e);
	// }
	//
	// static class TestMapper implements ParameterizedRowMapper<TestModel> {
	//
	// @Override
	// public TestModel mapRow(ResultSet rs, int rowNum) throws SQLException {
	// TestModel t = new MmochatRoleDao().new TestModel();
	//
	// t.setRoleId(rs.getInt("id"));
	// String str;
	// Gson gson = new Gson();
	// str = rs.getString("package");
	// if (str != null) {
	// Map<Integer, MmochatPackageGrid> myPackage = gson.fromJson(str,
	// new TypeToken<Map<Integer, MmochatPackageGrid>>() {
	// }.getType());
	// if (myPackage != null) {
	// t.setMyPackage(myPackage);
	// }
	// }
	//
	// str = rs.getString("storage");
	// if (str != null) {
	// Map<Integer, MmochatPackageGrid> myStorage = gson.fromJson(str,
	// new TypeToken<Map<Integer, MmochatPackageGrid>>() {
	// }.getType());
	// if (myStorage != null) {
	// t.setMyStorage(myStorage);
	// }
	// }
	//
	// return t;
	// }
	// }

	// TODO:END TEST

	// 获取前N名充值排名
	private static final String getTopPayListSql = "select id, skyid, name, "
			+ "total_pay from role order by total_pay desc limit ?";

	public List<MmochatRolePayInfo> getTopPayList(int topCount) {
		return getSimpleJdbcTemplate().query(getTopPayListSql,
				rolePayInfoMapper, topCount);
	}

	// 获取前30名等级排行
	private static final String getTopLevelListSql = "select id, name, friendlist_bmp,"
			+ "level, dao, small_money, stored_small_money, zhanji, "
			+ "coalesce(life_turn,0) as life_turn from role "
			+ "where delete = false order by life_turn desc,level desc,exp desc limit 30";

	public List<MmochatRankPlayer> getTopLevelList() {
		return getSimpleJdbcTemplate().query(getTopLevelListSql,
				rankRoleRowMapper);
	}

	// 获取前20名道行排行，一定等级内
	private static final String getTopDaoListByLevelSql = "select id, name, friendlist_bmp,"
			+ "level, dao, small_money, stored_small_money, zhanji, life_turn from role "
			+ "where delete = false and level >= ? and level <= ? order by dao desc limit 20";

	public List<MmochatRankPlayer> getTopDaoListByLevel(int minLevel,
			int maxLevel) {
		return getSimpleJdbcTemplate().query(getTopDaoListByLevelSql,
				rankRoleRowMapper, minLevel, maxLevel);
	}

	// 获取前30名道行排行
	private static final String getTopDaoListSql = "select id, name, friendlist_bmp,"
			+ "level, dao, small_money, stored_small_money, zhanji, life_turn from role "
			+ "where delete = false order by dao desc limit 30";

	public List<MmochatRankPlayer> getTopDaoList() {
		return getSimpleJdbcTemplate().query(getTopDaoListSql,
				rankRoleRowMapper);
	}

	// 获取前30名战绩排行
	private static final String getTopZhanjiListSql = "select id, name, friendlist_bmp,"
			+ "level, dao, small_money, stored_small_money, zhanji, life_turn from role "
			+ "where delete = false order by zhanji desc limit 30";

	public List<MmochatRankPlayer> getTopZhanjiList() {
		return getSimpleJdbcTemplate().query(getTopZhanjiListSql,
				rankRoleRowMapper);
	}

	// 获取前30名金钱排行
	private static final String getTopSmallMoneyListSql = "select id, name, friendlist_bmp,"
			+ "level, dao, small_money, stored_small_money, zhanji, life_turn from role "
			+ "where delete = false order by (stored_small_money+small_money) desc limit 30";

	public List<MmochatRankPlayer> getTopSmallMoneyList() {
		return getSimpleJdbcTemplate().query(getTopSmallMoneyListSql,
				rankRoleRowMapper);
	}

	// 获取skyId的角色列表
	private static final String getRoleListSql = "select id, name, level, family, latest_login_time"
			+ " from role where skyid = ? and delete = false order by level desc";

	public List<MmochatSimplePlayer> getRoleList(long skyId) {
		return getSimpleJdbcTemplate().query(getRoleListSql,
				simpleRoleRowMapper, skyId);
	}

	// 获取skyId的所有角色列表
	private static final String getAllRoleListSql = "select id, name, level, family, latest_login_time"
			+ " from role where skyid = ?";

	public List<MmochatSimplePlayer> getAllRoleList(long skyId) {
		return getSimpleJdbcTemplate().query(getAllRoleListSql,
				simpleRoleRowMapper, skyId);
	}

	// 获取指定roleId的角色
	private static final String getRoleSql = "select * from role "
			+ "where id = ? and delete = false";

	public MmochatPlayer getRole(int roleId) {
		try {
			return getSimpleJdbcTemplate().queryForObject(getRoleSql,
					roleMapper, roleId);
		} catch (EmptyResultDataAccessException e) {
			return null;
		}
	}

	// 获取指定roleId的角色，包括已删除角色
	private static final String getRoleIncludeDeletedSql = "select * from role "
			+ "where id = ?";

	public MmochatPlayer getRoleIncludeDeleted(int roleId) {
		try {
			return getSimpleJdbcTemplate().queryForObject(
					getRoleIncludeDeletedSql, roleMapper, roleId);
		} catch (EmptyResultDataAccessException e) {
			return null;
		}
	}

	// 获取指定name的角色，包括已删除角色
	private static final String getRoleByNameSql = "select * from role "
			+ "where name = ?";

	public MmochatPlayer getRoleByName(String name) {
		try {
			return getSimpleJdbcTemplate().queryForObject(getRoleByNameSql,
					roleMapper, name);
		} catch (EmptyResultDataAccessException e) {
			return null;
		}
	}

	// 创建新角色ID
	private static final String createNewRoleIdSql = "select nextval('role_id_seq'::regclass)";

	public int createNewRoleId() {
		return getSimpleJdbcTemplate().queryForInt(createNewRoleIdSql);
	}

	// 增加新的角色
	private static final String createRoleSql = "insert into role(skyid, name, sexual, family, "
			+ "type, friendlist_bmp, latest_login_time, latest_offline_time, suggest_name, create_time, imei,"
			+ "life_turn,second_role_type,lock_time_point, pk_score)"
			+ " values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)";

	public void createRole(long skyId, String name, int sexual, int family,
			int roleTypeValue, int friendListBmp, String suggest_name,
			String imei) {
		getSimpleJdbcTemplate().update(createRoleSql, skyId, name, sexual,
				family, roleTypeValue, friendListBmp, (new Date()).getTime(),
				(new Date()).getTime(), suggest_name,
				new Timestamp(System.currentTimeMillis()), imei, 0, 0, 0);
	}

	// 增加新的角色
	private static final String createRole2Sql = "insert into role(id, skyid, name, sexual, family, "
			+ "type, friendlist_bmp, latest_login_time, latest_offline_time, suggest_name, create_time, imei,"
			+ "life_turn,second_role_type,lock_time_point,small_money,big_money,level,pk_score)"
			+ " values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)";

	public void createRole2(int roleId, long skyId, String name, int sexual,
			int family, int roleTypeValue, int friendListBmp,
			String suggest_name, String imei, long createTime, int smallMoney,
			int bigMoney, int level) {
		getSimpleJdbcTemplate().update(createRole2Sql, roleId, skyId, name,
				sexual, family, roleTypeValue, friendListBmp,
				(new Date()).getTime(), (new Date()).getTime(), suggest_name,
				new Timestamp(createTime), imei, 0, 0, 0, smallMoney, bigMoney,
				level);
	}

	// 删除角色
	private static final String delRoleSql = "update role set delete = ? where id = ?";

	public void delRole(int id, boolean delete) {
		getSimpleJdbcTemplate().update(delRoleSql, delete, id);
	}

	// 更新角色第一次登陆游戏
	private static final String updateRoleFirstEnterGameSql = "update role set "
			+ "package = ?, storage = ?, tasks = ?, login_time = ? where id = ?";

	public void updateRoleFirstEnterGame(String myPackage, String myStorage,
			String tasks, int login_time, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleFirstEnterGameSql, myPackage,
				myStorage, tasks, login_time, roleId);
	}

	// 批量更新角色离开地图信息
	private static final String batchUpdateRoleLeaveGameSql = "update role set cur_blood = ?,"
			+ "cur_sprit = ? ,pets = ?, prop_effects = ?, "
			+ "map = ?, line = ?, x = ?, y = ?, myfans = ?, myidols = ?, accept_stranger_message = ?,"
			+ "check_addmefriend = ?, accept_addmefriend = ?, package = ?, tasks = ?,"
			+ "latest_offline_time = ?, latest_login_time = ?, level = ?,"
			+ "exp = ?, dao = ?, zhanji = ?, blood_point = ?, attack_point = ?,"
			+ "sprit_point = ?, speed_point = ?, space_point = ?, small_money = ?,"
			+ "big_money = ?, teacher_score = ?, attack_gift_point = ?, sprit_gift_point = ?,"
			+ "blood_gift_point = ?, defend_gift_point = ?, speed_gift_point = ?,"
			+ "space_gift_point = ?, cur_month_login_day_num = ?, "
			+ "friends = ?, name = ?, daily_activities = ?, fubenid = ?,"
			+ "special_skills = ?, pk_score = ?, life_skills = ? where id = ?";

	public void batchUpdateRoleLeaveGame(List<Object[]> args) {
		getSimpleJdbcTemplate().batchUpdate(batchUpdateRoleLeaveGameSql, args);
	}

	// 更新角色换线
	private static final String updateRoleChangeLineSql = "update role set line = ? where id = ?";

	public void updateRoleChangeLine(int line, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleChangeLineSql, line, roleId);
	}

	// 更新任务集合
	public static final String updateRoleTasksSql = "update role set tasks = ? "
			+ "where id = ?";

	public void updateRoleTasks(String gsonTasks, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleTasksSql, gsonTasks, roleId);
	}

	// 吃药品后更新：更新药品集合,人当前气血，法力，宠
	public static final String updateRoleAfterEatDrugSql = "update role set package = ?, cur_blood = ?, "
			+ "cur_sprit = ?, pets = ? where id = ?";

	public void updateRoleAfterEatDrug(String gsonPackage, int curBlood,
			int curSprit, String gsonPets, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleAfterEatDrugSql, gsonPackage,
				curBlood, curSprit, gsonPets, roleId);
	}

	// 购买药品
	public static final String buyDrugSql = "update role set package = ?, small_money = small_money - ? "
			+ "where id = ?";

	public void buyDrug(String gsonPackage, int moneyNeed, int roleId) {
		getSimpleJdbcTemplate().update(buyDrugSql, gsonPackage, moneyNeed,
				roleId);
	}

	// 购买物品
	public static final String buySmallMoneyObjSql = "update role set package = ?, small_money = small_money - ? "
			+ "where id = ?";

	public void buySmallMoneyObj(String gsonPackage, int moneyNeed, int roleId) {
		getSimpleJdbcTemplate().update(buySmallMoneyObjSql, gsonPackage,
				moneyNeed, roleId);
	}

	// 购买物品
	public static final String buyBigMoneyObjSql = "update role set package = ?, big_money = big_money - ? "
			+ ",limit_bigmoney = ? where id = ?";

	public void buyBigMoneyObj(String gsonPackage, int moneyNeed,
			long limit_bigmoney, int roleId) {
		getSimpleJdbcTemplate().update(buyBigMoneyObjSql, gsonPackage,
				moneyNeed, limit_bigmoney, roleId);
	}

	// 出售装备
	public static final String sellEquipSql = "update role set package = ?, small_money = small_money + ? "
			+ "where id = ?";

	public void sellEquip(String gsonPackage, int moneyAward, int roleId) {
		getSimpleJdbcTemplate().update(sellEquipSql, gsonPackage, moneyAward,
				roleId);
	}

	// 购买宠物
	public static final String buyPetSql = "update role set pets = ?, small_money = small_money - ? "
			+ "where id = ?";

	public void buyPet(String pet, int moneyNeed, int roleId) {
		getSimpleJdbcTemplate().update(buyPetSql, pet, moneyNeed, roleId);
	}

	// 增加角色金钱
	private static final String addRoleSmallMoneySql = "update role set small_money = small_money + ? "
			+ "where id = ?";

	public void addRoleSmallMoney(int id, int addMoney) {
		getSimpleJdbcTemplate().update(addRoleSmallMoneySql, addMoney, id);
	}

	// 更新角色未使用的装备,药品,材料,宠物,道具信息
	public static final String updateRoleAfterDealSql = "update role set package = ?, "
			+ " pets = ? where id = ?";

	public void updateRoleAfterDeal(String gsonPackage, String gsonPets,
			int roleId) {
		getSimpleJdbcTemplate().update(updateRoleAfterDealSql, gsonPackage,
				gsonPets, roleId);
	}

	// 批量更新角色交易完成后的数据
	public static final String batchUpdateRoleAfterDealSql = "update role "
			+ "set small_money = small_money + ?, package = ?, pets = ? where id = ?";

	public void batchUpdateRoleAfterDeal(List<Object[]> args) {
		getSimpleJdbcTemplate().batchUpdate(batchUpdateRoleAfterDealSql, args);
	}

	// 更新技能列表
	public static final String updateRoleSkillsSql = "update role set skills = ?, "
			+ "small_money = small_money - ? where id = ?";

	public void updateRoleSkills(String gsonSkills, int needSmallMoney,
			int roleId) {
		getSimpleJdbcTemplate().update(updateRoleSkillsSql, gsonSkills,
				needSmallMoney, roleId);
	}

	// 更新宠物列表
	public static final String updateRolePetsSql = "update role set pets = ? "
			+ "where id = ?";

	public void updateRolePets(String gsonPets, int roleId) {
		getSimpleJdbcTemplate().update(updateRolePetsSql, gsonPets, roleId);
	}

	// 更新宠物、包裹
	public static final String updateRolePetAndPackageSql = "update role set pets = ?, package = ? "
			+ "where id = ?";

	public void updateRolePetAndPackage(String gsonPets, String gsonPackage,
			int roleId) {
		getSimpleJdbcTemplate().update(updateRolePetAndPackageSql, gsonPets,
				gsonPackage, roleId);
	}

	// 更新好友列表
	public static final String updateMyFriendsSql = "update role set friends = ? "
			+ "where id = ?";

	public void updateMyFriends(String gsonFriends, int roleId) {
		getSimpleJdbcTemplate().update(updateMyFriendsSql, gsonFriends, roleId);
	}

	// 更新好友列表和元宝
	public static final String updateMyFriendsAndDelBigMoneySql = "update role set friends = ?,"
			+ "big_money = big_money - ?, limit_bigmoney = ? where id = ?";

	public void updateMyFriendsAndDelBigMoney(String gsonFriends,
			int delBigMoney, long limit_bigmoney, int roleId) {
		getSimpleJdbcTemplate().update(updateMyFriendsAndDelBigMoneySql,
				gsonFriends, delBigMoney, limit_bigmoney, roleId);
	}

	// 更新黑名单列表
	public static final String updateMyEnermysSql = "update role set enermys = ?, friends = ? "
			+ "where id = ?";

	public void updateMyEnermys(String gsonEnermys, String gsonFriend,
			int roleId) {
		getSimpleJdbcTemplate().update(updateMyEnermysSql, gsonEnermys,
				gsonFriend, roleId);
	}

	// 同时更新好友和黑名单
	public static final String updateMyFriendsAndEnermysSql = "update role set enermys = ?, friends = ? "
			+ "where id = ?";

	public void updateMyFriendsAndEnermys(String gsonEnermys,
			String gsonFriends, int roleId) {
		getSimpleJdbcTemplate().update(updateMyFriendsAndEnermysSql,
				gsonEnermys, gsonFriends, roleId);
	}

	// 更新任务
	public static final String updateRoleAfterTaskSql = "update role set level = ?, exp = ?, dao = ?, zhanji = ?, "
			+ "cur_blood = ?, cur_sprit = ?, blood_point = ?, attack_point = ?, sprit_point = ?, "
			+ "speed_point = ?, space_point = ?, small_money = ?, "
			+ "pets = ?, tasks = ?, prop_effects = ?, big_money = ?, teacher_score = ?, package = ?,"
			+ "attack_gift_point = ?, sprit_gift_point = ?, blood_gift_point = ?,"
			+ "defend_gift_point = ?, speed_gift_point = ?, space_gift_point = ? where id = ?";

	public void updateRoleAfterTask(int i, int j, int k, int l, int m, int n,
			int o, int p, int q, int r, int s, int t, String string,
			String string2, String string3, int u, int v, String string4,
			int w, int x, int y, int z, int a, int b, int c) {
		getSimpleJdbcTemplate().update(updateRoleAfterTaskSql, i, j, k, l, m,
				n, o, p, q, r, s, t, string, string2, string3, u, v, string4,
				w, x, y, z, a, b, c);
	}

	// 批量更新打怪后的数据
	public static final String batchUpdateRoleBaseInfoSql = "update role set level = ?, exp = ?, dao = ?, zhanji = ?, "
			+ "cur_blood = ?, cur_sprit = ?, blood_point = ?, attack_point = ?, sprit_point = ?, "
			+ "speed_point = ?, space_point = ?, small_money = ?, "
			+ "pets = ?, big_money = ?, teacher_score = ?, package = ?,"
			+ "attack_gift_point = ?, sprit_gift_point = ?, blood_gift_point = ?,"
			+ "defend_gift_point = ?, speed_gift_point = ?, space_gift_point = ?, friends = ? where id = ?";

	public void batchUpdateSqlAfterBattle(List<Object[]> args) {
		getSimpleJdbcTemplate().batchUpdate(batchUpdateRoleBaseInfoSql, args);
	}

	// 角色加点:属性点，空白属性点
	private static final String updateRolePointSql = "update role set blood_point = ?, "
			+ "attack_point = ?, sprit_point = ?, speed_point = ?, space_point = ?, "
			+ "attack_gift_point = ?, sprit_gift_point = ?, blood_gift_point = ?, "
			+ "defend_gift_point = ?, speed_gift_point = ?, space_gift_point = ? where id = ?";

	public void updateRolePoint(MmochatPlayer me) {
		getSimpleJdbcTemplate().update(updateRolePointSql, me.getBlood_point(),
				me.getAttack_point(), me.getSprit_point(), me.getSpeed_point(),
				me.getSpace_point(), me.getAttack_gift_point(),
				me.getSprit_gift_point(), me.getBlood_gift_point(),
				me.getDefend_gift_point(), me.getSpeed_gift_point(),
				me.getSpace_gift_point(), me.getRoleId());
	}

	// 角色加天赋:天赋点，空白天赋点
	private static final String updateRoleGiftPointSql = "update role set attack_gift_point = ?, "
			+ "sprit_gift_point = ?, blood_gift_point = ?, defend_gift_point = ?, speed_gift_point = ?, "
			+ "space_gift_point = ? where id = ?";

	public void updateRoleGiftPoint(MmochatPlayer me) {
		getSimpleJdbcTemplate().update(updateRoleGiftPointSql,
				me.getAttack_gift_point(), me.getSprit_gift_point(),
				me.getBlood_gift_point(), me.getDefend_gift_point(),
				me.getSpeed_gift_point(), me.getSpace_gift_point(),
				me.getRoleId());
	}

	// 更新钱庄游戏币
	public static final String updateStoreMoneySql = "update role set stored_small_money = ?, small_money = ?"
			+ " where id = ?";

	public void updateStoreMoney(int storedSmallMoney, int smallMoney,
			int roleId) {
		getSimpleJdbcTemplate().update(updateStoreMoneySql, storedSmallMoney,
				smallMoney, roleId);
	}

	// 更新钱庄宠物
	public static final String updateStorePetSql = "update role set stored_pets = ? where id = ?";

	public void updateStorePet(String gsonStoredPets, int roleId) {
		getSimpleJdbcTemplate().update(updateStorePetSql, gsonStoredPets,
				roleId);
	}

	// 更新每日领药活动
	public static final String updateFreeDrugActivitySql = "update role set package = ?, daily_activities = ? "
			+ "where id = ?";

	public void updateFreeDrugActivity(String gsonPackage,
			String gsonDailyActivities, int roleId) {
		getSimpleJdbcTemplate().update(updateFreeDrugActivitySql, gsonPackage,
				gsonDailyActivities, roleId);

	}

	// 更新道具效果(并更新道具可能影响的值)
	public static final String updateRolePropEffectsSql = "update role set name = ?,"
			+ "level = ?, exp = ?, map = ?, x = ?, y = ?, cur_blood = ?, cur_sprit = ?,"
			+ "blood_point = ?, attack_point = ?, sprit_point = ?, speed_point = ?, small_money = ?,"
			+ "big_money = ?, space_point = ?, dao = ?, zhanji = ?, "
			+ "package = ?, pets = ?, prop_effects = ?, "
			+ "attack_gift_point = ?, sprit_gift_point = ?, blood_gift_point = ?,"
			+ "defend_gift_point = ?, speed_gift_point = ?, space_gift_point = ?, "
			+ "daily_activities = ?, special_skills = ?, life_skills = ? where id = ?";

	public void updateRoleAfterUseProp(String name, int level, int exp,
			int mapId, int x, int y, int curBlood, int curSprit,
			int bloodPoint, int attackPoint, int spritPoint, int speedPoint,
			int smallMoney, int bigMoney, int spacePoint, int dao, int zhanji,
			String gsonPackage, String gsonPets, String gsonPropEffects,
			int attack_gift_point, int sprit_gift_point, int blood_gift_point,
			int defend_gift_point, int speed_gift_point, int space_gift_point,
			String dailyActivities, String specialSkills, String lifeSkills,
			int roleId) {
		getSimpleJdbcTemplate().update(updateRolePropEffectsSql, name, level,
				exp, mapId, x, y, curBlood, curSprit, bloodPoint, attackPoint,
				spritPoint, speedPoint, smallMoney, bigMoney, spacePoint, dao,
				zhanji, gsonPackage, gsonPets, gsonPropEffects,
				attack_gift_point, sprit_gift_point, blood_gift_point,
				defend_gift_point, speed_gift_point, space_gift_point,
				dailyActivities, specialSkills, lifeSkills, roleId);
	}

	// 改名
	public static final String updateRoleNameSql = "update role set name = ?, package = ? "
			+ "where id = ?";

	public void updateRoleName(String newName, String gsonPackage, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleNameSql, newName, gsonPackage,
				roleId);
	}

	// 改造装备
	public static final String modifyEquipSql = "update role set package = ?, "
			+ "small_money = small_money - ? where id = ?";

	public void modifyEquip(String gsonPackage, int smallMoneyNeed, int roleId) {
		getSimpleJdbcTemplate().update(modifyEquipSql, gsonPackage,
				smallMoneyNeed, roleId);
	}

	// 更新玩家显示设置
	public static final String updateRoleShowSetSql = "update role set show_role_set_value = ? "
			+ "where id = ?";

	public void updateRoleShowSet(int show_role_set_value, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleShowSetSql,
				show_role_set_value, roleId);
	}

	// 更新聊天频道设置
	public static final String updateRoleChatSetSql = "update role set show_chat_set = ? "
			+ "where id = ?";

	public void updateRoleChatSet(String show_chat_set, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleChatSetSql, show_chat_set,
				roleId);
	}

	// 更新玩家切磋设置
	public static final String updateRoleFriendlyPkSql = "update role set accept_friendlypk = ? "
			+ "where id = ?";

	public void updateRoleFriendlyPk(boolean accept_friendlypk, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleFriendlyPkSql,
				accept_friendlypk, roleId);
	}

	// 更新玩家比武设置
	public static final String updateRoleZhanjiPkSql = "update role set accept_zhanjipk = ? "
			+ "where id = ?";

	public void updateRoleZhanjiPk(boolean accept_zhanjipk, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleZhanjiPkSql, accept_zhanjipk,
				roleId);
	}

	// 更新玩家其它设置
	public static final String updateRoleOtherSettingSql = "update role set other_system_setting = ? "
			+ "where id = ?";

	public void updateRoleOtherSetting(String setting, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleOtherSettingSql, setting,
				roleId);
	}

	// 更新角色死亡
	private static final String updateRoleDeadSql = "update role set cur_blood = ?,"
			+ "cur_sprit = ? ,pets = ?, package = ?, prop_effects = ?, "
			+ "map = ?, x = ?, y = ?, exp = ?, dao = ?, small_money = ?, daily_activities = ? where id = ?";

	public void updateRoleDead(int curBlood, int curSprit, String gsonPets,
			String gsonPackage, String gsonPropEffects, int mapId, int x,
			int y, int exp, int dao, int smallMoney, String activity, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleDeadSql, curBlood, curSprit,
				gsonPets, gsonPackage, gsonPropEffects, mapId, x, y, exp, dao,
				smallMoney, activity, roleId);
	}

	public static final String updateRoleGetVipDoubleSql = "update role set latest_get_vip_doubleprop_time = ?, "
			+ "prop_effects = ? where id = ?";

	public void updateRoleGetVipDouble(long lastGetVipDoublePropTime,
			String propEffect, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleGetVipDoubleSql,
				lastGetVipDoublePropTime, propEffect, roleId);
	}

	// 加入帮派
	public static final String enjorGangSql = "update role set gang_id = ? where id = ?";

	public void enjorGang(int gang_id, int roleId) {
		getSimpleJdbcTemplate().update(enjorGangSql, gang_id, roleId);
	}

	// 加入战队
	public static final String enjorPkTeamSql = "update role set pkteam_id = ? where id = ?";

	public void enjorPkTeam(int team_id, int roleId) {
		getSimpleJdbcTemplate().update(enjorPkTeamSql, team_id, roleId);
	}

	// 更新玩家帮派技能
	public static final String updateRoleGangSkillSql = "update role set gang_skills = ? "
			+ "where id = ?";

	public void updateRoleGangSkill(String gangSkills, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleGangSkillSql, gangSkills,
				roleId);
	}

	// 更新角色游戏币
	private static final String updateRoleSmallMoneySql = "update role set small_money = ? "
			+ "where id = ?";

	public void updateRoleSmallMoney(int id, int money) {
		getSimpleJdbcTemplate().update(updateRoleSmallMoneySql, money, id);
	}

	// 更新角色师徒信息
	private static final String updateRoleTeacherAndStudentSql = "update role set teacher_roleid = ?, "
			+ "teacher_name = ?, students = ? where id = ?";

	public void updateRoleTeacherAndStudent(int teacher_roleid,
			String teacher_name, String students, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleTeacherAndStudentSql,
				teacher_roleid, teacher_name, students, roleId);
	}

	// 更新角色师傅信息
	private static final String updateRoleTeacherSql = "update role set teacher_roleid = ?,"
			+ " teacher_name = ? where id = ?";

	public void updateRoleTeacher(int teacher_roleid, String teacher_name,
			int roleId) {
		getSimpleJdbcTemplate().update(updateRoleTeacherSql, teacher_roleid,
				teacher_name, roleId);
	}

	// 出师
	private static final String graduteSql = "update role set package = ?, "
			+ "teacher_roleid = -1, teacher_name = null where id = ?";

	public void gradute(String gsonPackage, int roleId) {
		getSimpleJdbcTemplate().update(graduteSql, gsonPackage, roleId);
	}

	// 领取师傅工资
	private static final String getTeacherSalarySql = "update role set package = ?, teacher_score = 0"
			+ " where id = ?";

	public void getTeacherSalary(String myPackage, int roleId) {
		getSimpleJdbcTemplate().update(getTeacherSalarySql, myPackage, roleId);
	}

	// 更新战绩
	public static final String updateRoleZhanjiSql = "update role set zhanji = ? "
			+ "where id = ?";

	public void updateRoleZhanji(int zhanji, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleZhanjiSql, zhanji, roleId);
	}

	// 更新同屏显示上限
	public static final String updateScreenRoleNumSql = "update role set screen_role_num = ? "
			+ "where id = ?";

	public void updateScreenRoleNum(int screenRoleNum, int roleId) {
		getSimpleJdbcTemplate().update(updateScreenRoleNumSql, screenRoleNum,
				roleId);
	}

	// 更新包裹
	public static final String updateMyPackageSql = "update role set "
			+ "package = ?, small_money = ? where id = ?";

	public void updateMyPackage(String gsonMyPackage, int smallMoney, int roleId) {
		getSimpleJdbcTemplate().update(updateMyPackageSql, gsonMyPackage,
				smallMoney, roleId);

	}

	// 批量更新包裹
	public static final String batchUpdateMyPackageSql = "update role set "
			+ "package = ?, small_money = ? where id = ?";

	public void batchUpdateMyPackage(List<Object[]> args) {
		getSimpleJdbcTemplate().batchUpdate(batchUpdateMyPackageSql, args);
	}

	// 更新包裹和仓库
	public static final String updateMyPackageAndStoreSql = "update role set "
			+ "package = ?, storage = ? where id = ?";

	public void updateMyPackageAndStorage(String gsonMyPackage,
			String gsonMyStorage, int roleId) {
		getSimpleJdbcTemplate().update(updateMyPackageAndStoreSql,
				gsonMyPackage, gsonMyStorage, roleId);

	}

	// 更新仓库
	public static final String updateMyStorageSql = "update role set "
			+ "storage = ? where id = ?";

	public void updateMyStorage(String gsonMyStorage, int roleId) {
		getSimpleJdbcTemplate().update(updateMyStorageSql, gsonMyStorage,
				roleId);

	}

	// 批量加金钱和元宝
	public static final String batchUpdateMoneySql = "update role set "
			+ "small_money = small_money + ?, big_money = big_money + ? where id = ?";

	public void batchUpdateMoney(List<Object[]> args) {
		getSimpleJdbcTemplate().batchUpdate(batchUpdateMoneySql, args);
	}

	// 更新日常活动和战绩
	public static final String updateRoleDailyActivityAndZhanJiSql = "update role set "
			+ "zhanji = ?, daily_activities = ? where id = ?";

	public void updateRoleDailyActivityAndZhanJi(int zhanJi, String Activity,
			int roleId) {
		getSimpleJdbcTemplate().update(updateRoleDailyActivityAndZhanJiSql,
				zhanJi, Activity, roleId);
	}

	// 更新日常活动和包裹
	public static final String updateRoleDailyActivityAndPackageSql = "update role set "
			+ "package = ?, daily_activities = ? where id = ?";

	public void updateRoleDailyActivityAndPackage(String myPackage,
			String Activity, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleDailyActivityAndPackageSql,
				myPackage, Activity, roleId);
	}

	// 更新日常活动和包裹和宠物
	public static final String updateRoleDailyActivityAndPackageAndPetSql = "update role set "
			+ "package = ?, daily_activities = ?, pets = ? where id = ?";

	public void updateRoleDailyActivityAndPackageAndPet(String myPackage,
			String Activity, String pets, int roleId) {
		getSimpleJdbcTemplate().update(
				updateRoleDailyActivityAndPackageAndPetSql, myPackage,
				Activity, pets, roleId);
	}

	// 更新日常活动
	public static final String updateRoleDailyActivitySql = "update role set "
			+ "daily_activities = ? where id = ?";

	public void updateRoleDailyActivity(String Activity, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleDailyActivitySql, Activity,
				roleId);
	}

	// 更新奖券及连续天数,最后领取时间
	public static final String updateRoleLotterySql = "update role set "
			+ "lottery = ?, sustained_lottery_days = ?, last_lottery_time = ?, dao = ? where id = ?";

	public void updateRoleLottery(int lottery, int sustainedLotteryDays,
			long lastLotteryTime, int dao, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleLotterySql, lottery,
				sustainedLotteryDays, lastLotteryTime, dao, roleId);
	}

	// 更新奖券和包裹
	public static final String updateRoleLotteryAndPackageSql = "update role set "
			+ "lottery = ?, package = ? where id = ?";

	public void updateRoleLotteryAndPackage(int lottery, String myPackage,
			int roleId) {
		getSimpleJdbcTemplate().update(updateRoleLotteryAndPackageSql, lottery,
				myPackage, roleId);
	}

	// 批量更新玩家包裹和仓库
	public static final String batchUpdatePackageAndStorageSql = "update role set "
			+ "package = ?, storage = ? where id = ?";

	public void batchUpdatePackageAndStorage(List<Object[]> args) {
		getSimpleJdbcTemplate().batchUpdate(batchUpdatePackageAndStorageSql,
				args);
	}

	// 批量更新玩家道具效果
	public static final String batchUpdateRolePropEffectSql = "update role set prop_effects = ? "
			+ "where id = ?";

	public void batchUpdateRolePropEffect(List<Object[]> args) {
		getSimpleJdbcTemplate().batchUpdate(batchUpdateRolePropEffectSql, args);
	}

	// 增加玩家道行
	public static final String addRoleDaoSql = "update role set "
			+ "dao = dao + ? where id = ?";

	public void addRoleDao(int roleId, int add) {
		getSimpleJdbcTemplate().update(addRoleDaoSql, add, roleId);
	}

	// 增加玩家经验
	public static final String addRoleExpSql = "update role set "
			+ "exp = exp + ? where id = ?";

	public void addRoleExp(int roleId, int add) {
		getSimpleJdbcTemplate().update(addRoleExpSql, add, roleId);
	}

	// 增加玩家战绩
	public static final String addRoleZhanJiSql = "update role set "
			+ "zhanji = zhanji + ? where id = ?";

	public void addRoleZhanJi(int roleId, int add) {
		getSimpleJdbcTemplate().update(addRoleZhanJiSql, add, roleId);
	}

	// 增加玩家元宝
	public static final String addRoleBigMoneySql = "update role set "
			+ "big_money = big_money + ? where id = ?";

	public void addRoleBigMoney(int roleId, int add) {
		getSimpleJdbcTemplate().update(addRoleBigMoneySql, add, roleId);
	}

	// 增加玩家奖券
	public static final String addRoleLotterySql = "update role set "
			+ "lottery = lottery + ? where id = ?";

	public void addRoleLottery(int addLottery, int roleId) {
		getSimpleJdbcTemplate().update(addRoleLotterySql, addLottery, roleId);
	}

	// 增加玩家等级和相应属性
	public static final String addRoleLevelAndAttrSql = "update role set "
			+ "level = ?, blood_point = ?, attack_point = ?, sprit_point = ?, speed_point = ?,"
			+ "space_point = ?, space_gift_point = ? where id = ?";

	public void addRoleLevelAndAttr(int level, int blood_point,
			int attack_point, int sprit_point, int speed_point,
			int space_point, int space_gift_point, int roleId) {
		getSimpleJdbcTemplate().update(addRoleLevelAndAttrSql, level,
				blood_point, attack_point, sprit_point, speed_point,
				space_point, space_gift_point, roleId);
	}

	// 增加抽奖次数
	public static final String addRoleAwardTimesSql = "update role set "
			+ "rest_award_times = rest_award_times + ? where id = ?";

	public void addRoleAwardTimes(int roleId, int add) {
		getSimpleJdbcTemplate().update(addRoleAwardTimesSql, add, roleId);
	}

	// 增加玩家元宝并更新最后一次充值时间
	public static final String addRoleBigMoneyAndUpdatePayTimeSql = "update role set "
			+ "big_money = big_money + ?, rest_award_times = rest_award_times + ?, "
			+ "latest_pay_time = ?, total_pay = total_pay + ?, dao = ?, exp = ? where id = ?";

	public void addRoleBigMoneyAndUpdatePayTime(int roleId, int add,
			int addAwardTimes, long time, int rmb, int dao, int exp) {
		getSimpleJdbcTemplate().update(addRoleBigMoneyAndUpdatePayTimeSql, add,
				addAwardTimes, time, rmb, dao, exp, roleId);
	}

	// 获取name对应的roleId
	private static final String getRoleIdByNameSql = "select id from role "
			+ "where name = ? limit 1";

	public int getRoleIdByName(String name) {
		return getSimpleJdbcTemplate().queryForInt(getRoleIdByNameSql, name);
	}

	// 获取累计总注册用户数
	private static final String getTotalRoleNumSql = "select count(id) from role";

	public int getTotalRoleNum() {
		return getSimpleJdbcTemplate().queryForInt(getTotalRoleNumSql);
	}

	// 获取元宝剩余总量
	private static final String getTotalBigMoneySql = "select "
			+ "sum(big_money) + sum(account_bigmoney) from role";

	public long getTotalBigMoney() {
		return getSimpleJdbcTemplate().queryForLong(getTotalBigMoneySql);
	}

	// 获取游戏币剩余总量
	private static final String getTotalSmallMoneySql = "select sum(small_money)"
			+ "+sum(stored_small_money)+sum(account_smallmoney) from role";

	public long getTotalSmallMoney() {
		return getSimpleJdbcTemplate().queryForLong(getTotalSmallMoneySql);
	}

	// 获取7天内登陆过，并且注册时间早于6天前的用户数
	private static final String getLoginNumIn7DaySql = "select count(id) from role "
			+ "where latest_login_time >= ? and create_time < ?";

	public int getLoginNumIn7Day(long t7, Timestamp t6) {
		return getSimpleJdbcTemplate()
				.queryForInt(getLoginNumIn7DaySql, t7, t6);
	}

	// 获取每月活跃用户数
	private static final String getMonthlyActivityRoleNumSql = "select count(id) from role "
			+ "where cur_month_login_day_num >= 2";

	public int getMonthlyActivityRoleNum() {
		return getSimpleJdbcTemplate()
				.queryForInt(getMonthlyActivityRoleNumSql);
	}

	// 获取当月总登陆用户数
	private static final String getMonthlyLoginRoleNumSql = "select count(id) from role "
			+ "where latest_login_time >= ?";

	public int getMonthlyLoginRoleNum(long lastMonthTime) {
		return getSimpleJdbcTemplate().queryForInt(getMonthlyLoginRoleNumSql,
				lastMonthTime);
	}

	// 获取当月总付费用户数
	private static final String getMonthlyPayRoleNumSql = "select count(id) from role "
			+ "where latest_pay_time >= ?";

	public int getMonthlyPayRoleNum(long lastMonthTime) {
		return getSimpleJdbcTemplate().queryForInt(getMonthlyPayRoleNumSql,
				lastMonthTime);
	}

	// 更新积分和元宝
	private static final String updateSuggestScoreAndBigmoneySql = "update role set "
			+ "suggest_score = suggest_score - ?, big_money = big_money + ? where id = ?";

	public void updateSuggestScoreAndBigmoney(int delSuggestScore,
			int addBigMoney, int roleId) {
		getSimpleJdbcTemplate().update(updateSuggestScoreAndBigmoneySql,
				delSuggestScore, addBigMoney, roleId);
	}

	// 给推荐人增加积分
	private static final String addSuggestScoreSql = "update role set "
			+ "suggest_score = suggest_score + ? where id = ?";

	public int addSuggestScore(int addScore, int roleId) {
		return getSimpleJdbcTemplate().update(addSuggestScoreSql, addScore,
				roleId);
	}

	// 更新包裹、宠物、游戏币、道行和抽奖次数
	private static final String updateRoleAfterAwardSql = "update role set "
			+ "package = ?, pets = ?, suggest_score = suggest_score + ?, "
			+ "small_money = ?, dao = ?, rest_award_times = ? where id = ?";

	public void updateRoleAfterAward(String myPackage, String pets,
			int addSuggestScore, int smallMoney, int dao, int rest_award_times,
			int roleId) {
		getSimpleJdbcTemplate().update(updateRoleAfterAwardSql, myPackage,
				pets, addSuggestScore, smallMoney, dao, rest_award_times,
				roleId);
	}

	// 更新宠物列表和宠物仓库
	private static final String updateRolePetsAfterStoreSql = "update role set "
			+ "pets = ?, stored_pets = ? where id = ?";

	public void updateRolePetsAfterStore(String gsonPets,
			String gsonStoredPets, int roleId) {
		getSimpleJdbcTemplate().update(updateRolePetsAfterStoreSql, gsonPets,
				gsonStoredPets, roleId);
	}

	// 批量更新玩家元宝、金钱、账户元宝、账户金钱、限制元宝数量
	public static final String updateRoleAfterBigMoneyDealSql = "update role set "
			+ "big_money = big_money + ?, small_money = small_money + ?,"
			+ "account_bigmoney = account_bigmoney + ?, account_smallmoney = account_smallmoney + ?"
			+ ",limit_bigmoney = ? where id = ?";

	public void updateRoleAfterBigMoneyDeal(int big_money, int small_money,
			int account_bigmoney, int account_smallmoney, long limit_bigmoney,
			int roleId) {
		getSimpleJdbcTemplate().update(updateRoleAfterBigMoneyDealSql,
				big_money, small_money, account_bigmoney, account_smallmoney,
				limit_bigmoney, roleId);
	}

	// 批量更新玩家元宝、金钱、账户元宝、账户金钱
	public static final String updateRoleAfterBigMoneyDeal2Sql = "update role set "
			+ "big_money = big_money + ?, small_money = small_money + ?,"
			+ "account_bigmoney = account_bigmoney + ?, account_smallmoney = account_smallmoney + ?"
			+ " where id = ?";

	public void updateRoleAfterBigMoneyDeal2(int big_money, int small_money,
			int account_bigmoney, int account_smallmoney, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleAfterBigMoneyDeal2Sql,
				big_money, small_money, account_bigmoney, account_smallmoney,
				roleId);
	}

	// 批量更新玩家账户元宝、账户金钱
	public static final String batchUpdateRoleAfterBigMoneyDealTimeOutSql = "update role set "
			+ "account_bigmoney = account_bigmoney + ?, account_smallmoney = account_smallmoney + ?"
			+ " where id = ?";

	public void batchUpdateRoleAfterBigMoneyDealTimeOut(List<Object[]> args) {
		getSimpleJdbcTemplate().batchUpdate(
				batchUpdateRoleAfterBigMoneyDealTimeOutSql, args);
	}

	// 从交易账户取出元宝
	private static final String getBigMoneyFromDealAccountSql = "update role set "
			+ "big_money = big_money + ?, account_bigmoney = account_bigmoney - ?"
			+ " where id = ?";

	public void getBigMoneyFromDealAccount(int getValue, int roleId) {
		getSimpleJdbcTemplate().update(getBigMoneyFromDealAccountSql, getValue,
				getValue, roleId);
	}

	// 从交易账户取出金钱
	private static final String getSmallMoneyFromDealAccountSql = "update role set "
			+ "small_money = small_money + ?, account_smallmoney = account_smallmoney - ? where id = ?";

	public void getSmallMoneyFromDealAccount(int getValue, int roleId) {
		getSimpleJdbcTemplate().update(getSmallMoneyFromDealAccountSql,
				getValue, getValue, roleId);
	}

	// 读取所有玩家的等级信息(最近7天登陆过的)
	private static final String getAllPlayerLevelInfoSql = "select level,latest_offline_time from role "
			+ "where latest_offline_time > ?";

	public List<MmochatRoleLevelInfoStatistics> getAllPlayerLevelInfo(long time) {
		return getSimpleJdbcTemplate().query(getAllPlayerLevelInfoSql,
				roleLevelInfoRowMapper, time);
	}

	// 结婚
	private static final String marrySql = "update role set wife_roleid = ?, "
			+ "wife_name = ?, small_money = small_money - ? where id = ?";

	public void marry(int wife_roleId, String wife_name, int delMoney,
			int roleId) {
		getSimpleJdbcTemplate().update(marrySql, wife_roleId, wife_name,
				delMoney, roleId);
	}

	// 单独更新包裹
	private static final String updatePackageOnlySql = "update role set package = ? where id = ?";

	public void updatePackageOnly(String myPackage, int roleId) {
		getSimpleJdbcTemplate().update(updatePackageOnlySql, myPackage, roleId);
	}

	// 地图守护神:保存道行、宠物、每日任务、金钱
	private static final String saveMapGuiderDataSql = "update role set "
			+ "dao = dao + ?, pets = ?, daily_activities = ?, zhanji = ? where id = ?";

	public void saveMapGuiderData(int addDao, String pets,
			String daily_activities, int zhanJi, int roleId) {
		getSimpleJdbcTemplate().update(saveMapGuiderDataSql, addDao, pets,
				daily_activities, zhanJi, roleId);
	}

	// 保存称号
	private static final String saveChenhaoSql = "update role set chenhao = ? where id = ?";

	public void saveChenhao(String chenhao, int id) {
		getSimpleJdbcTemplate().update(saveChenhaoSql, chenhao, id);
	}

	// 增加道行并更新称号
	public static final String addRoleDaoAndUpdateChenhaoSql = "update role set "
			+ "chenhao = ?, dao = dao + ? where id = ?";

	public void addRoleDaoAndUpdateChenhao(String chenhao, int add, int roleId) {
		getSimpleJdbcTemplate().update(addRoleDaoAndUpdateChenhaoSql, chenhao,
				add, roleId);
	}

	// 更新角色游戏币及称号
	private static final String updateRoleSmallMoneyAndChenhaoSql = "update role set small_money = ?,"
			+ " chenhao = ? where id = ?";

	public void updateRoleSmallMoneyAndChenhao(int id, int money, String chenhao) {
		getSimpleJdbcTemplate().update(updateRoleSmallMoneyAndChenhaoSql,
				money, chenhao, id);
	}

	// 更新任务集合和称号
	public static final String updateRoleTasksAndChenhaoSql = "update role set tasks = ?, chenhao = ? "
			+ "where id = ?";

	public void updateRoleTasksAndChenhao(String gsonTasks, String chenhao,
			int roleId) {
		getSimpleJdbcTemplate().update(updateRoleTasksAndChenhaoSql, gsonTasks,
				chenhao, roleId);
	}

	// 更新包裹、元宝、道行
	public static final String updateRolePackage_BigMoney_DaoSql = "update role set package = ?,"
			+ "dao = dao + ?, big_money = big_money + ? where id = ?";

	public void updateRolePackage_BigMoney_Dao(String pack, int addDao,
			int addBigMoney, int roleId) {
		getSimpleJdbcTemplate().update(updateRolePackage_BigMoney_DaoSql, pack,
				addDao, addBigMoney, roleId);
	}

	// 转生
	public static final String rebornSql = "update role set level = ?, exp = ?, "
			+ "blood_point = ?, attack_point = ?, sprit_point = ?, speed_point = ?, space_point = ?, "
			+ "attack_gift_point = ?, sprit_gift_point = ?, blood_gift_point = ?, "
			+ "defend_gift_point = ?, speed_gift_point = ?, space_gift_point = ?, "
			+ "life_turn = ?, second_role_type = ? where id = ?";

	public void reborn(MmochatPlayer me) {
		getSimpleJdbcTemplate().update(rebornSql, me.getLevel(), me.getExp(),
				me.getBlood_point(), me.getAttack_point(), me.getSprit_point(),
				me.getSpeed_point(), me.getSpace_point(),
				me.getAttack_gift_point(), me.getSprit_gift_point(),
				me.getBlood_gift_point(), me.getDefend_gift_point(),
				me.getSpeed_gift_point(), me.getSpace_gift_point(),
				me.getLife_turn(), me.getSecond_role_type().getValue(),
				me.getRoleId());
	}

	// 仙魔转换
	public static final String changSecondRoleTypeSql = "update role set second_role_type = ?,"
			+ "big_money = big_money - ?, limit_bigmoney = ? where id = ?";

	public void changSecondRoleType(MmochatSecondRoleType roleType,
			int costBigMoney, long limit_bigmoney, int roleId) {
		getSimpleJdbcTemplate().update(changSecondRoleTypeSql,
				roleType.getValue(), costBigMoney, limit_bigmoney, roleId);
	}

	// 封号到一定时间
	public static final String forbiddenRoleSql = "update role set lock_time_point = ? where id = ?";

	public void forbiddenRole(long tick, int roleId) {
		getSimpleJdbcTemplate().update(forbiddenRoleSql, tick, roleId);
	}

	// 保存经验、道行
	public static final String saveExpAndDaoSql = "update role set exp = ?, dao = ? where id = ?";

	public void saveExpAndDao(int exp, int dao, int roleId) {
		getSimpleJdbcTemplate().update(saveExpAndDaoSql, exp, dao, roleId);
	}

	// 保存包裹、道行、战绩、游戏币
	public static final String savePackageDaoZhanJiSmallMoneySql = "update role "
			+ "set package = ?, dao = ?, zhanji = ?, small_money = small_money + ? where id = ?";

	public void savePackageDaoZhanJiSmallMoney(String gsonPackage, int dao,
			int zhanJi, int addSmallMoney, int roleId) {
		getSimpleJdbcTemplate().update(savePackageDaoZhanJiSmallMoneySql,
				gsonPackage, dao, zhanJi, addSmallMoney, roleId);
	}

	// 增加声望
	public static final String setHonorSql = "update role set honor = ? where id = ?";

	public void setHonor(long honor, int roleId) {
		getSimpleJdbcTemplate().update(setHonorSql, honor, roleId);
	}

	// 保存声望和经验、道行
	public static final String saveHonorExpDaoSql = "update role set honor = ?, exp = ?, dao = ?"
			+ " where id = ?";

	public void saveHonorExpDao(long honor, int exp, int dao, int roleId) {
		getSimpleJdbcTemplate().update(saveHonorExpDaoSql, honor, exp, dao,
				roleId);
	}

	// 保存声望和包裹
	public static final String saveHonorAndPackageSql = "update role set honor = ?, package = ?"
			+ " where id = ?";

	public void saveHonorAndPackage(long honor, String pack, int roleId) {
		getSimpleJdbcTemplate().update(saveHonorAndPackageSql, honor, pack,
				roleId);
	}

	// 保存声望和宠物
	public static final String saveHonorAndPetsSql = "update role set honor = ?, pets = ?"
			+ " where id = ?";

	public void saveHonorAndPets(long honor, String pet, int roleId) {
		getSimpleJdbcTemplate().update(saveHonorAndPetsSql, honor, pet, roleId);
	}

	// 保存声望和金钱
	public static final String saveHonorAndSmallMoneySql = "update role set honor = ?,"
			+ " small_money = small_money - ? where id = ?";

	public void saveHonorAndSmallMoney(long honor, int delSmallMoney, int roleId) {
		getSimpleJdbcTemplate().update(saveHonorAndSmallMoneySql, honor,
				delSmallMoney, roleId);
	}

	// 创建钱庄密码
	public static final String createStorePwdSql = "update role set store_pwd = ?,"
			+ "store_pwd_state = ?, release_store_pwd_time = ? where id = ?";

	public void createStorePwd(String pwd, int state,
			long release_store_pwd_time, int roleId) {
		getSimpleJdbcTemplate().update(createStorePwdSql, pwd, state,
				release_store_pwd_time, roleId);
	}

	// 读取role表总记录数
	public static final String getRoleNumSql = "select max(id) from role_other";

	public int getRoleNum() {
		return getSimpleJdbcTemplate().queryForInt(getRoleNumSql);
	}

	public static final String getMergeStep2Model1Sql = "select friends,enermys,students"
			+ ",id from role_other where (friends!='' or enermys!='' or students!= '')"
			+ " and id >= ? and id < ?";

	public List<MergeStep2Model1> getMergeStep2Model1(int start, int end) {
		return getSimpleJdbcTemplate().query(getMergeStep2Model1Sql,
				mergeStep2Model1Mapper, start, end);
	}

	public static final String updateMergeStep2Model1Sql = "update role_other set friends = ?, "
			+ "enermys = ?, students = ? where id = ?";

	public void updateMergeStep2Model1(List<Object[]> args) {
		getSimpleJdbcTemplate().batchUpdate(updateMergeStep2Model1Sql, args);
	}

	public static final String updateExtraAndPackageSql = "update role set extra = ?,"
			+ "package = ? where id = ?";

	public void updateExtraAndPackage(long extra, String packageStr, int id) {
		getSimpleJdbcTemplate().update(updateExtraAndPackageSql, extra,
				packageStr, id);
	}

	// 更新副本完成奖励
	public static final String updateRoleAfterFuBenSql = "update role set "
			+ "daily_activities = ?, package = ?, exp = ?, level = ?, dao = ?,"
			+ "fubenid = ?, pets = ?, small_money = ? where id = ?";

	public void updateRoleAfterFuBen(String daily_activities,
			String gsonPackage, int exp, int level, int dao, int fubenid,
			String pets, int small_money, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleAfterFuBenSql,
				daily_activities, gsonPackage, exp, level, dao, fubenid, pets,
				small_money, roleId);
	}

	// 更新秘籍技能
	public static final String updateRoleSpecialSkillSql = "update role set "
			+ "special_skills = ? where id = ?";

	public void updateRoleSpecialSkill(String special_skills, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleSpecialSkillSql,
				special_skills, roleId);
	}

	// 训练技能熟练度
	public static final String trainRoleSpecialSkillSql = "update role set "
			+ "big_money = ?, special_skills = ?, daily_activities = ? where id = ?";

	public void trainRoleSpecialSkill(int big_money, String special_skills,
			String daily_activities, int roleId) {
		getSimpleJdbcTemplate().update(trainRoleSpecialSkillSql, big_money,
				special_skills, daily_activities, roleId);
	}

	// 使用道具后，变更门派
	public static final String changeFamilySql = "update role set "
			+ "skills = ?, family = ?, type = ?, package = ? where id = ?";

	public void changeFamily(String skills, int family, int roleType,
			String gsonPackage, int roleId) {
		getSimpleJdbcTemplate().update(changeFamilySql, skills, family,
				roleType, gsonPackage, roleId);
	}

	// 变更性别
	public static final String changeSexSql = "update role set "
			+ "sexual = ?, type = ?, friendlist_bmp = ? where id = ?";

	public void changeSex(int sex, int type, int bmpId, int roleId) {
		getSimpleJdbcTemplate().update(changeSexSql, sex, type, bmpId, roleId);
	}

	// 读取竞技点
	public static final String getPkScoreSql = "select pk_score from role where id = ?";

	public Integer getPkScore(int roleId) {
		return getSimpleJdbcTemplate().queryForInt(getPkScoreSql, roleId);
	}

	// 更新竞技点
	public static final String updatePkScoreSql = "update role set pk_score = ? where id = ?";

	public void updatePkScore(int score, int roleId) {
		getSimpleJdbcTemplate().update(updatePkScoreSql, score, roleId);
	}

	// 更新生活技能
	public static final String updateLifeSkillSql = "update role set life_skills = ? where id = ?";

	public void updateLifeSkill(String life_skills, int roleId) {
		getSimpleJdbcTemplate().update(updateLifeSkillSql, life_skills, roleId);
	}

	// 更新生活技能和宠物列表
	public static final String updateLifeSkillAndPetsSql = "update role set pets = ?, "
			+ "life_skills = ?, daily_activities = ? where id = ?";

	public void updateLifeSkillAndPets(String gsonPets, String life_skills,
			String dailyActivity, int roleId) {
		getSimpleJdbcTemplate().update(updateLifeSkillAndPetsSql, gsonPets,
				life_skills, dailyActivity, roleId);
	}

	// 保存心情
	public static final String updateMoodSql = "update role set mood = ? where id = ?";

	public void updateMood(String mood, int roleId) {
		getSimpleJdbcTemplate().update(updateMoodSql, mood, roleId);
	}

	// 更新包裹、元宝、道行、经验、战绩
	public static final String updateRoleOnlineAwardSql = "update role set package = ?,"
			+ "dao = ?, big_money = ?, exp = ?, zhanji = ? where id = ?";

	public void updateRoleOnlineAward(String pack, int addDao, int addBigMoney,
			int addExp, int addZhangji, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleOnlineAwardSql, pack, addDao,
				addBigMoney, addExp, addZhangji, roleId);
	}

	// 按IMEI获取前N个用户
	private static final String getRoleByImeiSql = "select id, skyid, name, "
			+ "total_pay from role where imei = ? limit ?";

	public List<MmochatRolePayInfo> getRoleByImei(String imei, int limitNum) {
		return getSimpleJdbcTemplate().query(getRoleByImeiSql,
				rolePayInfoMapper, imei, limitNum);
	}

	// 更新玩家诚信信息
	public static final String setChiefRecordSql = "update role set  mood = ?, other_system_setting = ? "
			+ "where id = ?";

	public void setChiefRecord(String mood, String setting, int roleId) {
		getSimpleJdbcTemplate()
				.update(setChiefRecordSql, mood, setting, roleId);
	}

	// 更新SkyId
	public static final String updateRoleSkyIdSql = "update role set skyid = ? where id = ?";

	public void updateRoleSkyId(long newSkyId, int roleId) {
		getSimpleJdbcTemplate().update(updateRoleSkyIdSql, newSkyId, roleId);
	}

	// 获取包裹、仓库、宠物，仓库宠物
	public static final String getMergeStep1Model1Sql = "select package, storage, pets, stored_pets "
			+ "from role where id = ? and (position('borrowFromRoleId' in package) > 0 "
			+ "or position('borrowFromRoleId' in storage) > 0 "
			+ "or position('borrowFromRoleId' in pets) > 0 "
			+ "or position('borrowFromRoleId' in stored_pets) > 0)";

	public MergeStep1Model1 getMergeStep1Model1(int roleId) {
		try {
			return getSimpleJdbcTemplate().queryForObject(
					getMergeStep1Model1Sql, mergeStep1Mapper, roleId);
		} catch (EmptyResultDataAccessException e) {
			return null;
		}
	}

	// 更新包裹、仓库、宠物，仓库宠物
	public static final String updateMergeStep1Model1Sql = "update role set "
			+ "package = ?, storage = ?, pets = ?, stored_pets = ? where id = ?";

	public void updateMergeStep1Model1(String packageStr, String storage,
			String pets, String stored_pets, int roleId) {
		getSimpleJdbcTemplate().update(updateMergeStep1Model1Sql, packageStr,
				storage, pets, stored_pets, roleId);
	}

	// 获取包裹、仓库、仓库宠物
	public static final String getMergeStep1Model4Sql = "select package, storage, stored_pets "
			+ "from role where id = ?";

	public MergeStep1Model4 getMergeStep1Model4(int roleId) {
		try {
			return getSimpleJdbcTemplate().queryForObject(
					getMergeStep1Model4Sql, mergeStep4Mapper, roleId);
		} catch (EmptyResultDataAccessException e) {
			return null;
		}
	}

	// 更新包裹、仓库、仓库宠物
	public static final String updateMergeStep1Model4Sql = "update role set "
			+ "package = ?, storage = ?, stored_pets = ? where id = ?";

	public void updateMergeStep1Model4(String packageStr, String storage,
			String stored_pets, int roleId) {
		getSimpleJdbcTemplate().update(updateMergeStep1Model4Sql, packageStr,
				storage, stored_pets, roleId);
	}

	public int commonUpdate(String sql) {
		return getSimpleJdbcTemplate().update(sql);
	}

	public List<MmochatPlayer> commonQuery(String sql) {
		return getSimpleJdbcTemplate().query(sql, roleMapper);
	}

	public MmochatPlayer commonQueryForObject(String sql) {
		return getSimpleJdbcTemplate().queryForObject(sql, roleMapper);
	}

	public static class MergeStep1Mapper implements
			ParameterizedRowMapper<MergeStep1Model1> {
		@Override
		public MergeStep1Model1 mapRow(ResultSet rs, int rowNum)
				throws SQLException {
			MergeStep1Model1 m = new MergeStep1Model1();
			m.setPackageStr(rs.getString("package"));
			m.setStorageStr(rs.getString("storage"));
			m.setPets(rs.getString("pets"));
			m.setStored_pets(rs.getString("stored_pets"));
			return m;
		}
	}

	public static class MergeStep4Mapper implements
			ParameterizedRowMapper<MergeStep1Model4> {
		@Override
		public MergeStep1Model4 mapRow(ResultSet rs, int rowNum)
				throws SQLException {
			MergeStep1Model4 m = new MergeStep1Model4();
			m.setPackageStr(rs.getString("package"));
			m.setStorageStr(rs.getString("storage"));
			m.setStored_pets(rs.getString("stored_pets"));
			return m;
		}
	}

	public static class SimpleRoleRowMapper implements
			ParameterizedRowMapper<MmochatSimplePlayer> {
		@Override
		public MmochatSimplePlayer mapRow(ResultSet rs, int rowNum)
				throws SQLException {
			MmochatSimplePlayer role = new MmochatSimplePlayer();
			role.setRoleId(rs.getInt("id"));
			role.setName(rs.getString("name"));
			role.setLevel(rs.getInt("level"));
			role.setFamily(MmochatFamilyType.get(rs.getInt("family")));
			role.setLatest_login_time(rs.getLong("latest_login_time"));
			return role;
		}
	}

	static class RankRoleRowMapper implements
			ParameterizedRowMapper<MmochatRankPlayer> {
		@Override
		public MmochatRankPlayer mapRow(ResultSet rs, int rowNum)
				throws SQLException {
			MmochatRankPlayer role = new MmochatRankPlayer();
			role.setRoleId(rs.getInt("id"));
			role.setName(rs.getString("name"));
			role.setBmpId(rs.getInt("friendlist_bmp"));
			role.setLevel(rs.getInt("level"));
			role.setDao(rs.getInt("dao"));
			role.setSmall_money(rs.getInt("small_money"));
			role.setStoredSmall_money(rs.getInt("stored_small_money"));
			role.setZhanji(rs.getInt("zhanji"));
			role.setLife_turn(rs.getInt("life_turn"));
			return role;
		}
	}

	static class RoleLevelInfoRowMapper implements
			ParameterizedRowMapper<MmochatRoleLevelInfoStatistics> {
		@Override
		public MmochatRoleLevelInfoStatistics mapRow(ResultSet rs, int rowNum)
				throws SQLException {
			MmochatRoleLevelInfoStatistics role = new MmochatRoleLevelInfoStatistics();
			role.setLevel(rs.getInt("level"));
			role.setLatest_offline_time(rs.getLong("latest_offline_time"));
			return role;
		}
	}

	static class RolePayInfoRowMapper implements
			ParameterizedRowMapper<MmochatRolePayInfo> {
		@Override
		public MmochatRolePayInfo mapRow(ResultSet rs, int rowNum)
				throws SQLException {
			MmochatRolePayInfo info = new MmochatRolePayInfo();
			info.setName(rs.getString("name"));
			info.setRoleId(rs.getInt("id"));
			info.setSkyId(rs.getLong("skyid"));
			info.setTotal_pay(rs.getInt("total_pay"));
			return info;
		}
	}

	static class MergeStep2Model1Mapper implements
			ParameterizedRowMapper<MergeStep2Model1> {
		@Override
		public MergeStep2Model1 mapRow(ResultSet rs, int rowNum)
				throws SQLException {
			if (rs == null) {
				return null;
			}
			MergeStep2Model1 role = new MergeStep2Model1();
			Gson gson = new Gson();

			role.setId(rs.getInt("id"));

			String str = rs.getString("friends");
			if (str != null) {
				Map<Integer, MmochatFriend> friends = gson.fromJson(str,
						new TypeToken<Map<Integer, MmochatFriend>>() {
						}.getType());
				if (friends != null) {
					role.setMyDearFriends(friends);
				}
			}
			str = rs.getString("enermys");
			if (str != null) {
				Map<Integer, MmochatFriend> enermys = gson.fromJson(str,
						new TypeToken<Map<Integer, MmochatFriend>>() {
						}.getType());
				if (enermys != null) {
					role.setMyEnermys(enermys);
				}
			}

			str = rs.getString("students");
			if (str != null) {
				Map<Integer, String> students = gson.fromJson(str,
						new TypeToken<Map<Integer, String>>() {
						}.getType());
				if (students != null) {
					role.setStudents(students);
				}
			}

			return role;
		}
	}

	static class RoleRowMapper implements ParameterizedRowMapper<MmochatPlayer> {
		@Override
		public MmochatPlayer mapRow(ResultSet rs, int rowNum)
				throws SQLException {
			MmochatPlayer role = new MmochatPlayer();
			role.setRoleId(rs.getInt("id"));
			role.setDeleted(rs.getBoolean("delete"));
			role.setSkyId(rs.getLong("skyid"));
			role.setName(rs.getString("name"));
			role.setLevel(rs.getInt("level"));
			role.setExp(rs.getInt("exp"));
			role.setSexual(rs.getInt("sexual"));
			role.setMapId(rs.getInt("map"));
			role.setLine(rs.getInt("line"));
			role.setX(rs.getInt("x"));
			role.setY(rs.getInt("y"));
			role.setRoleType(MmochatRoleType.get(rs.getInt("type")));
			role.setCurBlood(rs.getInt("cur_blood"));
			role.setCurSprit(rs.getInt("cur_sprit"));
			role.setBlood_point(rs.getInt("blood_point"));
			role.setAttack_point(rs.getInt("attack_point"));
			role.setSprit_point(rs.getInt("sprit_point"));
			role.setSpeed_point(rs.getInt("speed_point"));
			role.setSpace_point(rs.getInt("space_point"));
			role.setSmall_money(rs.getInt("small_money"));
			role.setBig_money(rs.getInt("big_money"));
			role.setFamily(MmochatFamilyType.get(rs.getInt("family")));
			role.setDao(rs.getInt("dao"));
			role.setZhanji(rs.getInt("zhanji"));
			role.setLogin_time(rs.getInt("login_time"));
			role.setLatest_login_time(rs.getLong("latest_login_time"));
			role.setLatest_offline_time(rs.getLong("latest_offline_time"));
			role.setStoredSmall_money(rs.getInt("stored_small_money"));
			role.setCur_month_login_day_num(rs
					.getInt("cur_month_login_day_num"));

			Integer show_role_set_value = rs.getInt("show_role_set_value");
			if (show_role_set_value != null) {
				MmochatShowRoleSet set = MmochatShowRoleSet
						.get(show_role_set_value);
				if (set != null) {
					role.setShowRoleSet(set);
				}
			}

			role.setAcceptFriendlyPk(rs.getBoolean("accept_friendlypk"));
			role.setAcceptZhanjiPk(rs.getBoolean("accept_zhanjipk"));
			role.setLastGetVipDoublePropTime(rs
					.getLong("latest_get_vip_doubleprop_time"));

			role.setBmpId(rs.getInt("friendlist_bmp"));
			role.setMoodInfo(rs.getString("mood"));
			role.setAcceptStrangerMessage(rs
					.getBoolean("accept_stranger_message"));
			role.setCheckAddMeFriend(rs.getBoolean("check_addmefriend"));
			role.setAcceptAddMeFriend(rs.getBoolean("accept_addmefriend"));
			role.setGangId(rs.getInt("gang_id"));
			role.setPkteam_id(rs.getInt("pkteam_id"));
			role.setTeacher_roleId(rs.getInt("teacher_roleid"));
			role.setTeacher_name(rs.getString("teacher_name"));
			role.setTeacherScore(rs.getInt("teacher_score"));
			role.setMax_screen_role_num(rs.getInt("screen_role_num"));
			role.setAttack_gift_point(rs.getInt("attack_gift_point"));
			role.setSprit_gift_point(rs.getInt("sprit_gift_point"));
			role.setBlood_gift_point(rs.getInt("blood_gift_point"));
			role.setDefend_gift_point(rs.getInt("defend_gift_point"));
			role.setSpeed_gift_point(rs.getInt("speed_gift_point"));
			role.setSpace_gift_point(rs.getInt("space_gift_point"));
			String suggestName = rs.getString("suggest_name");
			if (suggestName != null && suggestName.length() > 0) {
				role.setSuggestName(suggestName);
			}
			role.setImei(rs.getString("imei"));
			role.setSuggestScore(rs.getInt("suggest_score"));
			role.setCreateTime(rs.getTimestamp("create_time").getTime());
			role.setRest_award_times(rs.getInt("rest_award_times"));
			role.setLottery(rs.getInt("lottery"));
			role.setSustainedLotteryDays(rs.getInt("sustained_lottery_days"));
			role.setLastLotteryTime(rs.getLong("last_lottery_time"));

			role.setAccount_bigmoney(rs.getInt("account_bigmoney"));
			role.setAccount_smallmoney(rs.getInt("account_smallmoney"));
			role.setWife_roleId(rs.getInt("wife_roleid"));
			String wifeName = rs.getString("wife_name");
			if (wifeName != null && wifeName.length() > 0) {
				role.setWife_name(wifeName);
			}
			role.setTotal_pay(rs.getInt("total_pay"));

			Integer lifeTurn = rs.getInt("life_turn");
			if (lifeTurn != null) {
				role.setLife_turn(lifeTurn);
			}

			Integer second_role_type = rs.getInt("second_role_type");
			if (second_role_type != null) {
				role.setSecond_role_type(MmochatSecondRoleType
						.get(second_role_type));
			}

			Long lock_time_point = rs.getLong("lock_time_point");
			if (lock_time_point != null) {
				role.setLock_time_point(lock_time_point);
			}

			Long honor = rs.getLong("honor");
			if (honor != null) {
				role.setHonor(honor);
			}

			String pwd = rs.getString("store_pwd");
			if (pwd != null) {
				role.setStore_pwd(pwd);
			}

			Integer store_pwd_state = rs.getInt("store_pwd_state");
			if (store_pwd_state != null) {
				MmochatStorePwdState state = MmochatStorePwdState
						.get(store_pwd_state);
				if (state != null) {
					role.setStore_pwd_state(state);
				}
			}

			Long release_store_pwd_time = rs.getLong("release_store_pwd_time");
			if (release_store_pwd_time != null) {
				role.setReleaseStorePwdTime(release_store_pwd_time);
			}

			Long extra = rs.getLong("extra");
			if (extra != null) {
				role.setExtra(extra);
			}

			Long limit_bigmoney = rs.getLong("limit_bigmoney");
			if (limit_bigmoney != null) {
				role.setLimit_bigmoney(limit_bigmoney);
			}

			Integer fuBenId = rs.getInt("fubenid");
			if (fuBenId != null) {
				role.setFuBenId(fuBenId);
			}

			Integer pkScore = rs.getInt("pk_score");
			if (pkScore != null) {
				role.setPk_score(pkScore);
			}

			Long latest_pay_time = rs.getLong("latest_pay_time");
			if (latest_pay_time != null) {
				role.setLatest_pay_time(latest_pay_time);
			}

			// TODO:GSON开始
			Gson gson = new Gson();

			String str = rs.getString("tasks");
			if (str != null && str.length() > 0) {
				Map<Integer, MmochatTask> tasks = gson.fromJson(str,
						new TypeToken<Map<Integer, MmochatTask>>() {
						}.getType());
				if (tasks != null) {
					role.setTasks(tasks);
				}
			}

			str = rs.getString("skills");
			if (str != null && str.length() > 0) {
				Map<MmochatSkillType, MmochatSkill> skills = gson.fromJson(str,
						new TypeToken<Map<MmochatSkillType, MmochatSkill>>() {
						}.getType());
				if (skills != null) {
					role.setSkills(skills);
				}
			}
			str = rs.getString("pets");
			if (str != null && str.length() > 0) {
				Map<Integer, MmochatPet> pets = gson.fromJson(str,
						new TypeToken<Map<Integer, MmochatPet>>() {
						}.getType());
				if (pets != null) {
					role.setPets(pets);
				}
			}
			str = rs.getString("friends");
			if (str != null && str.length() > 0) {
				Map<Integer, MmochatFriend> friends = gson.fromJson(str,
						new TypeToken<Map<Integer, MmochatFriend>>() {
						}.getType());
				if (friends != null) {
					role.setMyDearFriends(friends);
				}
			}
			str = rs.getString("enermys");
			if (str != null && str.length() > 0) {
				Map<Integer, MmochatFriend> enermys = gson.fromJson(str,
						new TypeToken<Map<Integer, MmochatFriend>>() {
						}.getType());
				if (enermys != null) {
					role.setMyEnermys(enermys);
				}
			}

			str = rs.getString("stored_pets");
			if (str != null && str.length() > 0) {
				Map<Integer, MmochatPet> stored_pets = gson.fromJson(str,
						new TypeToken<Map<Integer, MmochatPet>>() {
						}.getType());
				if (stored_pets != null) {
					role.setStoredPets(stored_pets);
				}
			}

			str = rs.getString("daily_activities");
			if (str != null && str.length() > 0) {
				Map<MmochatDailyActivityType, MmochatDailyActivity> daily_activities = gson
						.fromJson(
								str,
								new TypeToken<Map<MmochatDailyActivityType, MmochatDailyActivity>>() {
								}.getType());
				if (daily_activities != null) {
					role.setDailyActivities(daily_activities);
				}
			}

			str = rs.getString("prop_effects");
			if (str != null && str.length() > 0) {
				Map<Integer, MmochatPropEffect> prop_effects = gson.fromJson(
						str, new TypeToken<Map<Integer, MmochatPropEffect>>() {
						}.getType());
				if (prop_effects != null) {
					role.setPropEffects(prop_effects);
				}
			}

			str = rs.getString("show_chat_set");
			if (str != null && str.length() > 0) {
				Map<MmochatChatChannelType, Boolean> show_chat_set = gson
						.fromJson(
								str,
								new TypeToken<Map<MmochatChatChannelType, Boolean>>() {
								}.getType());
				if (show_chat_set != null) {
					role.setShowChatSet(show_chat_set);
				}
			}

			str = rs.getString("myfans");
			if (str != null && str.length() > 0) {
				Map<Integer, Integer> myfans = gson.fromJson(str,
						new TypeToken<Map<Integer, Integer>>() {
						}.getType());
				if (myfans != null) {
					role.setMyFans(myfans);
				}
			}

			str = rs.getString("myidols");
			if (str != null && str.length() > 0) {
				Map<Integer, Integer> myidols = gson.fromJson(str,
						new TypeToken<Map<Integer, Integer>>() {
						}.getType());
				if (myidols != null) {
					role.setMyIdols(myidols);
				}
			}

			str = rs.getString("gang_skills");
			if (str != null && str.length() > 0) {
				Map<MmochatGangSkillType, MmochatGangSkill> gangSkills = gson
						.fromJson(
								str,
								new TypeToken<Map<MmochatGangSkillType, MmochatGangSkill>>() {
								}.getType());
				if (gangSkills != null) {
					role.setGangSkills(gangSkills);
				}
			}

			str = rs.getString("students");
			if (str != null && str.length() > 0) {
				Map<Integer, String> students = gson.fromJson(str,
						new TypeToken<Map<Integer, String>>() {
						}.getType());
				if (students != null) {
					role.setStudents(students);
				}
			}

			str = rs.getString("package");
			if (str != null && str.length() > 0) {
				Map<Integer, MmochatPackageGrid> myPackage = gson.fromJson(str,
						new TypeToken<Map<Integer, MmochatPackageGrid>>() {
						}.getType());
				if (myPackage != null) {
					role.setMyPackage(myPackage);
				}
			}

			str = rs.getString("storage");
			if (str != null && str.length() > 0) {
				Map<Integer, MmochatPackageGrid> myStorage = gson.fromJson(str,
						new TypeToken<Map<Integer, MmochatPackageGrid>>() {
						}.getType());
				if (myStorage != null) {
					role.setMyStorage(myStorage);
				}
			}

			str = rs.getString("other_system_setting");
			if (str != null && str.length() > 0) {
				Map<MmochatOtherSystemSettingType, Boolean> otherSystemSetting = gson
						.fromJson(
								str,
								new TypeToken<Map<MmochatOtherSystemSettingType, Boolean>>() {
								}.getType());
				if (otherSystemSetting != null) {
					role.setOtherSystemSetting(otherSystemSetting);
				}
			}

			str = rs.getString("chenhao");
			if (str != null && str.length() > 0) {
				Map<MmochatChenHaoType, MmochatChenHao> chenHao = gson
						.fromJson(
								str,
								new TypeToken<Map<MmochatChenHaoType, MmochatChenHao>>() {
								}.getType());
				if (chenHao != null) {
					role.setChenHaoMap(chenHao);
				}
			}

			str = rs.getString("special_skills");
			if (str != null && str.length() > 0) {
				Map<MmochatSpecialSkillType, MmochatSpecialSkill> specialSkills = gson
						.fromJson(
								str,
								new TypeToken<Map<MmochatSpecialSkillType, MmochatSpecialSkill>>() {
								}.getType());
				if (specialSkills != null) {
					role.setSpecialSkills(specialSkills);
				}
			}

			str = rs.getString("life_skills");
			if (str != null && str.length() > 0) {
				Map<MmochatLifeSkillType, MmochatLifeSkill> lifeSkills = gson
						.fromJson(
								str,
								new TypeToken<Map<MmochatLifeSkillType, MmochatLifeSkill>>() {
								}.getType());
				if (lifeSkills != null) {
					role.setLifeSkills(lifeSkills);
				}
			}

			return role;
		}
	}

}
